/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package me.joshua.tools4j.web;

import me.joshua.tools4j.dal.ActionRepository;
import me.joshua.tools4j.model.Action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 
 * @author Joshua
 */
@Controller
@RequestMapping("/action")
public class ActionController {

//	private static final Logger	LOGGER	= LoggerFactory.getLogger(ActionController.class);

	@Autowired
	private ActionRepository	actionRepository;

	@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
	public String form(@PathVariable("id") Action action, Model model) {
		model.addAttribute("action", action);
		return "/action_form";
	}

	@RequestMapping(value = "/edit/{id}", method = RequestMethod.POST)
	public String edit(Action action, Model model) {
		action = actionRepository.save(action);
		return "refresh:";
	}

}
